module Formulario

  @@number_by_form = {
    :requerimento => 1,
    :cadastro_empreendimento => 2,
    :caracterizacao => 3,
    :documentos => 4
  }.freeze

  @@letter_by_incentivo = {
    :red_75_irpj => "A",
    :red_12_5_irpj => "B",
    :reinvestimento_30_irpj =>"C",
    :depreciacao_acelerada => "D",
    :isencao_afrmm_iof => "E"
  }.freeze

  def form_codes(formulario)
    number = @@number_by_form[formulario]
    form_letters(number).map {|letter| "#{number}#{letter}"}
  end

  private

  def form_letters(number)
    incentivo = mnemonic.to_sym
    case number
    when 1, 4 then
      @@letter_by_incentivo[incentivo]
    when 2 then 'A'..'C'
    when 3 then
      case incentivo
        when :red_75_irpj, :red_12_5_irpj then @@letter_by_incentivo[incentivo]
        when :reinvestimento_30_irpj      then 'C'..'E'
        when :depreciacao_acelerada       then 'F'
        when :isencao_afrmm_iof           then 'G'
      end
    else 'WTF'
    end
  end

end
